// 轮播图小按钮
var swiper_items_child=document.getElementsByClassName("swiper_items_child");
console.log("swiper_items_child",swiper_items_child);
var now_index_swiper=1;


// swiper_items_child_hide();
// swiper_items_child[now_index_swiper].className="active swiper_items_child";

// 第一个轮播图的元素
var boxa = document.getElementsByClassName("banner_a_swiper")[0];
var boxb = boxa.getElementsByClassName("banner_a_items");

var swiper_timera = "";//第一个轮播图的定时器
var now_page_a = 0;
// console.log(arr);
// 第1个轮播图的ul left偏移量
var swiper_left_a = 0;
// 第一个轮播图
// 向右轮播
function swiper_l() {
	swiper_timera = setInterval(function() {
		swiper_left_a -= boxb[0].clientWidth + 2;
		if (swiper_left_a <= -(boxb[0].clientWidth+2)*(boxb.length)) {
			swiper_left_a = 0;
		}else if(swiper_left_a%(boxb[0].clientWidth+2)!=0){
			console.log("buwei 000");
			clear_swiper_timera();
		}
		boxa.style.left = swiper_left_a + "px";
		btn_i();
	}, 5000)
}
// 清空轮播1 小按钮样式
function clear_child(){
	for(let i=0;i<swiper_items_child.length;i++){
		swiper_items_child[i].className="swiper_items_child";
	}
}
function btn_i(){
	clear_child();
	swiper_items_child[now_index_swiper].className="swiper_items_child active";
	now_index_swiper++;
	if(now_index_swiper==swiper_items_child.length){
		now_index_swiper=0;
	}
}
window.onresize = function() {
	clear_swiper_timera();
}
// 清空第一个轮播图的定时器
function clear_swiper_timera(){
	clearInterval(swiper_timera);
	swiper_left_a = 0;
	now_index_swiper=0;
	btn_i();
	// boxa.style.transitionDuration = "0s";
	boxa.style.left = 0 + "px";
	swiper_l();
}
swiper_l();


// 轮播图img2
(function(){
	var now_page_b=0;//img2的当前页
	var swiper_timerb = "";//第2个轮播图的定时器
	// 第2个轮播图的ul left偏移量
	var swiper_left_b=0;
	// 第2个轮播图的元素
	// 轮播图 2
	var wrapper_items_swiper_img_ul=document.getElementsByClassName("wrapper_items_swiper_img_ul")[0];
	var img2_items=wrapper_items_swiper_img_ul.getElementsByClassName("img2_items");
	// var img2_items=document.getElementsByClassName("img2_items");
	var navs_li=document.getElementsByClassName("navs_li");
	
	console.log("li的个数",img2_items.length);
	// 第2个轮播图
	// 向右轮播
	var swiper_l2=function(){
		swiper_timerb=setInterval(function(){
			swiper_left_b=-(img2_items[0].clientWidth*now_page_b);
			wrapper_items_swiper_img_ul.style.left=swiper_left_b+"px";
			// console.log("now_page_b",now_page_b);
			clear_img_activ();
			navs_li[now_page_b].className="navs_li img2_uli_active";
			now_page_b++;//0-7
			if(now_page_b>=navs_li.length){
				now_page_b=0;
			}
		},3000)
	}
	// img2的清空按钮激活类的class
	var clear_img_activ=function(){
		var ac_item=document.getElementsByClassName("img2_uli_active")[0];
		if(ac_item){
			ac_item.className="navs_li";
		}
	}
	
	// 设置点击后的classname
	var get_navli_index=function(p){
		clear_img_activ();//清空激活的选项
		p.target.className="navs_li img2_uli_active";
		now_page_b=p.target.index;//设置当前页 索引
		clearInterval(swiper_timerb);// 清空第2个轮播图的定时器
		swiper_left_b=-(img2_items[0].clientWidth*now_page_b);
		wrapper_items_swiper_img_ul.style.left=swiper_left_b+"px";
		swiper_l2();//继续开启定时器
		// console.log("now_page_b等于",i.target.index);
	}
	for(let i=0;i<navs_li.length;i++){
		navs_li[i].index=i;
		navs_li[i].onclick=get_navli_index;
		img2_items[i].index=i;
		img2_items[i].onmouseenter=function(){
			console.log("鼠标进入");
			clearInterval(swiper_timerb);// 清空第2个轮播图的定时器
		}
		img2_items[i].onmouseleave=function(){
			console.log("鼠标离开");
			swiper_l2();//继续开启定时器
		}
	}
	
	 swiper_l2();
})()
